import pyglet
from pyglet.gl import *
window = pyglet.window.Window(visible=False, resizable=True)

def on_resize(width, height):
	"""Setup 3D viewport"""
	glViewport(0, 0, width, height)
	glMatrixMode(GL_PROJECTION)
	glLoadIdentity()
	gluPerspective(70, 1.0*width/height, 0.1, 1000.0)
	glMatrixMode(GL_MODELVIEW)
	glLoadIdentity()
window.on_resize = on_resize
window.set_visible()

rot = 0 # <<<

@window.event
def on_draw():
	window.clear()
	glLoadIdentity()
	glTranslatef(0, 0, -2.5)
	glRotatef(rot, 1.0, 1.0, 1.0) # <<<
	glBegin(GL_QUADS)
	glColor3f(1.0, 0, 0)
	glVertex3f(1.0, -1.0, 0.0)
	glColor3f(1.0, 1.0, 0)
	glVertex3f(1.0, 1.0, 0.0)
	glColor3f(0, 1.0, 0)
	glVertex3f(-1.0, 1.0, 0.0)
	glColor3f(0, 0, 1.0)
	glVertex3f(-1.0, -1.0, 0.0)
	glEnd()

def update(dt):
	global rot
	rot += dt * 50.0
pyglet.clock.schedule_interval(update, 1.0/30.0)

pyglet.app.run()
